package ooday04homework;

public class PolymorphicDemo {
    public static void main(String[] args) {
        Animal[] animals = new Animal[3];
        animals[0] = new Dog("小黄", 2, "黄色");
        animals[1] = new Chick("小黑", 1, "黑色");
        animals[2] = new Fish("小花", 3, "花色");
        for (Animal animal : animals) {
            System.out.println(animal.name);
            animal.eat();
            animal.drink();

            if (animal instanceof Dog) {
                Dog dog = (Dog) animal;
                dog.lookHome();
            }

            if (animal instanceof Chick) {
                Chick chick = (Chick) animal;
                chick.layEggs();
            }

            if (animal instanceof Swim) {
                Swim swim = (Swim) animal;
                swim.swim();
            }
        }
        System.out.println("向上造型返回派生类");
        Master master = new Master();
        Dog dog = new Dog("小狗", 1, "黑色");
        Fish fish = new Fish("小鱼",1,"灰色");
        Chick chick = new Chick("小鸡",2,"红色");
        master.feed(dog);
        master.feed(fish);
        master.feed(chick);
    }
}
